var myFoot = {};
myFoot.methods = {};
$(function () {
    // 足迹 切换    
    myFoot.methods.myFootTab();
    
    //个体删除
    myFoot.methods.singleCornerDelete();
    
    // 删除当天
    myFoot.methods.dayCornerDelete();

    // 多选及批量删除
    myFoot.methods.allCornerDelete();

    // 多选及批量状态
    myFoot.methods.chooseCornerImg();

    //样式状态
    myFoot.methods.allCornerImg();
    
    //当天浏览数量
    myFoot.methods.seeBooks();

})

// 足迹 切换 
myFoot.methods.myFootTab = function () {
    myFoot.methods.bookClass = "1";
    $(".shop-user-MyFoot-cut li").on("click", function () {
        myFoot.methods.allCornerImg();
        $(this).addClass("shop-click").siblings().removeClass("shop-click");
        $(".shop-user-MyFoot-con").hide();
        myFoot.methods.bookClass = $(this).attr("shop-book-class");
        
        $(".shop-user-MyFoot-con[shop-book-class = "+ myFoot.methods.bookClass +"]").show();
    })
}


//删除个体
myFoot.methods.singleCornerDelete = function () {
    $(".shop-user-MyFoot-con-corner-delete").on("click", function () {
        if($(this).siblings(".shop-user-MyFoot-con-cornerBG").css("display") == "none"){
            var bookId = $(this).parents(".shop-user-MyFoot-con-corner").attr("shop-book-id");
            $(".shop-user-MyFoot-con-corner[shop-book-id = " + bookId + "]").remove();
            myFoot.methods.update();
            myFoot.methods.seeBooks();
        }
    })
}

// 删除当天
myFoot.methods.dayCornerDelete = function () {
    $(".shop-delete-day").on("click", function () {
        $(this).parents("li").find(".shop-user-MyFoot-con-corner").each(function () {
            var bookIdArr = $(this).attr("shop-book-id");
            $(".shop-user-MyFoot-con-corner[shop-book-id = " + bookIdArr + "]").remove();
            myFoot.methods.update();
            myFoot.methods.seeBooks();
        })
    })
}

// 多选及批量删除
myFoot.methods.allCornerDelete = function(){
    $(".shop-complete").click(function(){
        $(".shop-all-delete").show();
        $(".shop-all-complete").hide();
        $(".shop-delete-day").hide();
        $(".shop-user-MyFoot-con-cornerBG").hide();
        $(".shop-user-MyFoot-con-corner-delete").hide();
        $(".shop-user-MyFoot-con[shop-book-class="+myFoot.methods.bookClass+"]").find("ul > li .shop-user-MyFoot-con-corner").each(function(){
            if($(this).find(".shop-user-MyFoot-con-corner-delete").hasClass("shop-user-MyFoot-con-corner-delete-checked")){
                //$(this).remove();
                var bookIndexArr = $(this).attr("shop-book-id");
                $(".shop-user-MyFoot-con-corner[shop-book-id = " + bookIndexArr + "]").remove();
            }
        })
        
        myFoot.methods.update();
        myFoot.methods.seeBooks();
    })   
}

// 多选及批量状态
myFoot.methods.chooseCornerImg = function(){
    $(".shop-user-MyFoot-con-corner").on("click",function(){
        var bookId = $(this).attr("shop-book-id");
        if($(this).find(".shop-user-MyFoot-con-cornerBG").css("display") == "none"){
            return;
        }else{
            $(".shop-user-MyFoot-con-corner[shop-book-id = " + bookId + "]").find(".shop-user-MyFoot-con-corner-delete").toggleClass("shop-user-MyFoot-con-corner-delete-checked");
            var myFootConCornerLen = $(this).parents(".shop-user-MyFoot-con").find(".shop-user-MyFoot-con-corner").length;
            if($(this).parents(".shop-user-MyFoot-con").find(".shop-user-MyFoot-con-corner-delete-checked").length == myFootConCornerLen){
                $(".shop-all input").attr("checked",true);
            }else{
                $(".shop-all input").attr("checked",false);
            }
        }
    })
}

//公共清除父级
myFoot.methods.update = function () {
    $(".shop-user-MyFoot-con").find("ul > li").each(function () {
        if ($(this).find(".shop-user-MyFoot-con-corner").length == 0) {
            $(this).remove();
            $(".shop-all input").attr("checked",false);
        }
        
    });
}

//样式状态
myFoot.methods.allCornerImg = function () {
    // 初始状态
    $(".shop-all-delete").show();
    $(".shop-all-complete").hide();
    $(".shop-delete-day").hide();
    $(".shop-user-MyFoot-con-cornerBG").hide();
    $(".shop-user-MyFoot-con-corner-delete").hide();
    $(".shop-all input").attr("checked", false);
    $(".shop-user-MyFoot-con-corner-delete").removeClass("shop-user-MyFoot-con-corner-delete-checked");

    $(".shop-all-delete").on("click", function () {
            $(".shop-all-delete").hide();
            $(".shop-all-complete").show();
            $(".shop-delete-day").show();
            $(".shop-user-MyFoot-con-cornerBG").show();
            $(".shop-user-MyFoot-con-corner-delete").show();
    })

    $(".shop-all input").change(function () {
        if ($(".shop-all input").attr("checked")) {
            $(".shop-user-MyFoot-con-corner-delete").addClass("shop-user-MyFoot-con-corner-delete-checked");
        } else {
            $(".shop-user-MyFoot-con-corner-delete").removeClass("shop-user-MyFoot-con-corner-delete-checked");
        }
    })
}

//当天浏览数量
myFoot.methods.seeBooks = function(){
	$(".shop-user-MyFoot-con").find("ul > li").each(function () {
        if ($(this).find(".shop-user-MyFoot-con-corner").length == 0) {
            return;
        }else{
        	var bookNum = $(this).find(".shop-user-MyFoot-con-corner").length;
        	$(this).find(".shop-user-MyFoot-con-title span").text(bookNum +"件商品");
        }
    });
}
